<!--书架-->
<template>
  <transition name="home" enter-active-class="animated slideInLeft" leave-active-class="animated fadeOutLeft">
    <div class="bookshelf_home">
      <Headers></Headers>
      <bookList  @del_bookId = "del_selected"></bookList>
      
      <component style="z-index:99999999;" v-bind:is = "$store.state.footBar" :delBookId="delBookId"></component>
      <div id="delbox">
        <delBox></delBox>
      </div>
    </div>
  </transition>
</template>

<script>
  import Headers from '@/components/commons/header/header.vue'
  import handdle from '@/components/bookshelf/handdle.vue'
  import bookList from '@/components/bookshelf/bookList.vue'
  import buttomNav from '@/components/bookshelf/buttom_nav.vue'
  import buttomNav2 from '@/components/bookshelf/buttom_nav2.vue'
  import store from '@/store/index'
  import delBox from '@/components/xiaozujian/del_box.vue'
  import USER from '@/utils/user'
  export default {
    name: 'Bookshelf',
    data () {
      return {
        msg: 'Welcome to Your Vue.js App',
        footBar: buttomNav,
        delBookId: []
      }
    },
    store,
    beforeRouteLeave(to, from, next) {
        this.$route.meta.keepAlive=true;
        next();
    },
    created: function () {
      this.$store.commit('hidedel');
      this.$store.commit('empty_del');
      this.$store.commit('showButtomNav');
      this.getLoginInfo();
    },
    methods: {
      del_selected: function (bookId) {
        // 检查bookid是否存在，如果存在则删除该条数据，否则添加一条新数据
        var isEixsts = true
        for (var i = 0; i < this.delBookId.length; i++) {
          if (this.delBookId[i] === bookId) {
            this.delBookId.splice(i, 1)
            isEixsts = false
            break
          }
        }
        if (isEixsts) {
          this.delBookId.push(bookId)
        }
      },
      getLoginInfo(){ //获取登录信息,如果登录，重定向至登录页面
        var loginInfo = USER.getUserInfo();
        this.userInfo = loginInfo;
        if(loginInfo.isLogin==1){ //0已登录 1未登录
          this.$router.push({name:'login'});
          }
      },
    },
    components: {Headers, handdle, bookList, buttomNav, buttomNav2, delBox}
  }
</script>


<style>
.bookshelf_home{
  position: relative;
  min-height: 568px;
  background: #fff;
}

</style>
